home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 140 / demos / hilo.asm < prev    next >
Encoding:
Assembly Source File  |  1987-05-13  |  12.0 KB  |  452 lines

  1. ;-----------------------------------------------------------------------------;
  2. ;                                HILO.PRG                                     ;
  3. ;                                                                             ;
  4. ;This program demonstrates a method by which the screen resolution can be     ;
  5. ;changed at a specific scan line.  Using this method, the resolution can      ;
  6. ;be changed from low to medium in the middle of the screen.  Refer to         ;
  7. ;the comments in the source code to see how it is done.                       ;                                       ;
  8. ;-----------------------------------------------------------------------------;
  9. ;The following macro is needed because the assembler I am using will not
  10. ;generate these kinds of instructions automatically.
  11. ;
  12. ;MOVE.B #xxxx,$8aaa ;Short address move immediate
  13. ;
  14. MOVEBW MACRO
  15.   DC.W $11FC
  16.   DC.W \1
  17.   DC.W \2
  18.   ENDM
  19. ;
  20.   TEXT
  21. ;----------
  22. ;Start here
  23. ;
  24. BEGADR EQU *
  25. ;
  26.   MOVEM.L A0-A6/D0-D7,-(SP)
  27. ;
  28. ;Get into super mode
  29. ;
  30.   CLR.L -(SP)
  31.   MOVE.W #$20,-(SP)
  32.   TRAP #1
  33.   ADDQ #6,SP
  34.   MOVE.L D0,SAVE_SSP
  35. ;-------------------------------
  36. ;Download character set from ROM
  37. ;into local memory.  This is really not
  38. ;needed for the demonstration unless it is run
  39. ;on a machine with more than 512K.
  40. ;
  41.   LEA CHTAB,A6  ;Address of where character bit maps are to be stored
  42.   LEA ASCIT,A5  ;Ascii character codes
  43.   MOVEQ #95,D7  ;96 characters
  44. ;
  45. CHLOP MOVE.B (A5)+,MSG+4 ;Have TOS display the character at (0,0)
  46.   PEA MSG
  47.   MOVE.W #$9,-(SP)
  48.   TRAP #1
  49.   ADDQ.L #6,SP
  50. ;
  51.   MOVEQ #0,D0       ;Get screen address from the hardware
  52.   MOVE.B $FF8201,D0
  53.   SWAP D0
  54.   MOVE.B $FF8203,D0
  55.   LSL.W #8,D0
  56.   MOVE.L D0,A4
  57. ;
  58.   MOVEQ #7,D0       ;Move 8 bytes of bitmap data
  59. RASTLP MOVE.B (A4),(A6)+
  60.   ADD.W #160,A4
  61.   DBRA D0,RASTLP    ;Go back for more bytes
  62.   DBRA D7,CHLOP     ;Go back for more characters
  63. ;--------------------------------------------------
  64. ;Clear frame buffer (the display will be at $78000)
  65. ;
  66.   MOVE.W #7999,D0
  67.   MOVE.L #$78000,A1
  68.   MOVEQ #0,D1
  69. CLBL1 MOVE.L D1,(A1)+
  70.   DBRA D0,CLBL1
  71. ;-------------------
  72. ;Save color pallette
  73. ;
  74.   MOVE.L #$FF8240,A0
  75.   LEA ORGPAL,A1
  76.   MOVEQ #15,D0
  77. PALOP MOVE.W (A0)+,(A1)+
  78.   DBRA D0,PALOP
  79. ;---------------
  80. ;Save resolution
  81. ;
  82.   MOVE.B $FF8260,SAVREZ
  83. ;----------------------
  84. ;Save current address
  85. ;of display memory
  86. ;
  87.   MOVE.B $FF8201,SVSCR
  88.   MOVE.B $FF8203,SVSCR+1
  89. ;----------------------
  90. ;New pallette
  91. ;
  92.   LEA PALET,A0
  93.   MOVE.L #$FF8240,A1
  94.   MOVEQ #15,D0
  95. PALOP2 MOVE.W (A0)+,(A1)+
  96.   DBRA D0,PALOP2
  97. ;---------------------
  98. ;Disable certain 68901
  99. ;interupts.
  100. ;
  101. DSABL MOVE.W #5,-(SP) ;System timer
  102.   MOVE.W #26,-(SP)
  103.   TRAP #14
  104.   ADDQ.W #4,SP
  105. ;
  106.   MOVE.W #9,-(SP) ;RS232 transmit error
  107.   MOVE.W #26,-(SP)
  108.   TRAP #14
  109.   ADDQ.W #4,SP
  110. ;
  111.   MOVE.W #10,-(SP) ;RS232 transmit buffer empty
  112.   MOVE.W #26,-(SP)
  113.   TRAP #14
  114.   ADDQ.W #4,SP
  115. ;
  116.   MOVE.W #11,-(SP) ;RS232 receive error
  117.   MOVE.W #26,-(SP)
  118.   TRAP #14
  119.   ADDQ.W #4,SP
  120. ;
  121.   MOVE.W #12,-(SP) ;RS232 receive buffer full
  122.   MOVE.W #26,-(SP)
  123.   TRAP #14
  124.   ADDQ.W #4,SP
  125. ;
  126.   MOVE.L $466,D0 ;Wait for vertical blank
  127. W2 CMP.L $466,D0
  128.   BEQ.S W2
  129. ;------------------------------------------------
  130.   MOVEBW $07,$8201 ;Set display address to $78000
  131.   MOVEBW $80,$8203
  132. ;
  133.   MOVEBW $00,$8260 ;Set low rez
  134. ;------------------------------
  135. ;Fill screen with "A"
  136. ;
  137.   MOVE #24,D7   ;25 lines
  138.   LEA $78000,A1 ;Address of display memory
  139. ;
  140. OUTER MOVE.L A1,A2
  141.   MOVE.W #159,D6 ;160 characters per line (all 4 planes)
  142. ;
  143. INNER LEA CHTAB,A0
  144.   MOVE.W #(($41-$20)*8),D0
  145.   LEA 0(A0,D0.W),A0  ;Address of bit map for "A"
  146. ;
  147.   MOVE.B (A0)+,(A2)  ;Move bit map
  148.   MOVE.B (A0)+,160(A2)
  149.   MOVE.B (A0)+,320(A2)
  150.   MOVE.B (A0)+,480(A2)
  151.   MOVE.B (A0)+,640(A2)
  152.   MOVE.B (A0)+,800(A2)
  153.   MOVE.B (A0)+,960(A2)
  154.   MOVE.B (A0)+,1120(A2)
  155. ;
  156.   ADDQ.W #1,A2
  157.   DBRA D6,INNER
  158. ;
  159.   ADD.W #1280,A1
  160.   DBRA D7,OUTER
  161. ;-------------------------
  162. ;Replace Keyboard interupt
  163. ;vector.
  164. ;
  165.   MOVE.L $118,KVEC
  166.   LEA KINT,A0
  167.   MOVE.L A0,$118
  168. ;--------------------
  169. ;Point timer B vector
  170. ;Leave timer disabled.
  171. ;
  172.   PEA TIMERB        ;Address of timer routine
  173.   MOVE.W #$80,-(SP) ;Timer data register
  174.   MOVE.W #0,-(SP)   ;Timer control register (enabled and stopped)
  175.   MOVE.W #1,-(SP)   ;Select timer B
  176.   MOVE.W #31,-(SP)
  177.   TRAP #14
  178.   ADD.W #12,SP
  179. ;------------------
  180. ;Replace system VBI
  181. ;with my own.
  182. ;
  183.   MOVE.L $70,SYSVBI
  184.   LEA VBI,A0
  185.   MOVE.L A0,$70
  186. ;----------------------
  187. ;Bconstat - see if char
  188. ;was typed
  189. ;
  190. CHKEYS MOVE.W #2,-(SP)
  191.   MOVE.W #1,-(SP)
  192.   TRAP #13
  193.   ADDQ.W #4,SP
  194. ;
  195.   TST.W D0
  196.   BEQ.S CHKEYS
  197. ;----------------------
  198. ;Bconin - read raw char
  199. ;
  200.   MOVE.W #2,-(SP)
  201.   MOVE.W #2,-(SP)
  202.   TRAP #13
  203.   ADDQ.W #4,SP
  204. ;
  205.   CMP.B #3,D0 ;Cntrl-C ?
  206.   BEQ EXITP
  207. ;
  208.   MOVE.W D0,D1
  209.   LSR.L #8,D0
  210.   MOVE.B D1,D0
  211. ;--------------------------------
  212. CHKCUU CMP.W #$4800,D0 ;Cursor up
  213.   BNE.S CHKCUD
  214. ;
  215.   LEA CDATA,A0
  216.   CMP.W #$0000,(A0) ;Can't move up if already at the top
  217.   BEQ CHKEYS
  218. ;
  219.   SUBQ.W #1,(A0)  ;Modify timer B data register value (in VBI code)
  220.   BRA CHKEYS
  221. ;----------------------------------
  222. CHKCUD CMP.W #$5000,D0 ;Cursor down
  223.   BNE.S CHKEYS
  224. ;
  225.   LEA CDATA,A0
  226.   CMP.W #199,(A0) ;Can't move down if already at the bottom
  227.   BEQ CHKEYS
  228. ;
  229.   ADDQ.W #1,(A0)  ;Modify timer B data register value (in VBI code)
  230.   BRA CHKEYS
  231. ;-----------------
  232. ;Terminate program
  233. ;
  234. EXITP MOVE.L $466,D0 ;Wait for vertical blank
  235. W3 CMP.L $466,D0
  236.   BEQ.S W3
  237. ;-----------------------------------------------------------------
  238.   MOVE.L SYSVBI,$70 ;Restore system vertical blank interupt vector
  239. ;
  240.   MOVE.L $466,D0 ;Wait for vertical blank
  241. W4 CMP.L $466,D0
  242.   BEQ.S W4
  243. ;-------------------------------------------
  244.   MOVE.L KVEC,$118  ;Restore keyboard vector
  245. ;
  246. ;Restore original address
  247. ;of display memory
  248. ;
  249.   MOVE.B SVSCR,$FF8201
  250.   MOVE.B SVSCR+1,$FF8203
  251. ;
  252.   MOVEBW $00,$FA1B  ;Clear control register for timer B
  253. ;--------------------
  254. ;Reset color pallette
  255. ;
  256.   LEA ORGPAL,A0
  257.   MOVE.L #$FF8240,A1
  258.   MOVEQ #15,D0
  259. PALOP3 MOVE.W (A0)+,(A1)+
  260.   DBRA D0,PALOP3
  261. ;------------------
  262. ;Restore resolution
  263. ;
  264.   MOVE.B SAVREZ,$FF8260
  265. ;----------------------
  266. ;Re-enable 68901
  267. ;interupts.
  268. ;
  269.   MOVE.W #5,-(SP) ;System timer
  270.   MOVE.W #27,-(SP)
  271.   TRAP #14
  272.   ADDQ.W #4,SP
  273. ;
  274.   MOVE.W #9,-(SP) ;RS232 transmit error
  275.   MOVE.W #27,-(SP)
  276.   TRAP #14
  277.   ADDQ.W #4,SP
  278. ;
  279.   MOVE.W #10,-(SP) ;RS232 transmit buffer empty
  280.   MOVE.W #27,-(SP)
  281.   TRAP #14
  282.   ADDQ.W #4,SP
  283. ;
  284.   MOVE.W #11,-(SP) ;RS232 receive error
  285.   MOVE.W #27,-(SP)
  286.   TRAP #14
  287.   ADDQ.W #4,SP
  288. ;
  289.   MOVE.W #12,-(SP) ;RS232 receive buffer full
  290.   MOVE.W #27,-(SP)
  291.   TRAP #14
  292.   ADDQ.W #4,SP
  293. ;---------------------
  294. ;Get out of super mode
  295. ;
  296.   MOVE.L SAVE_SSP,-(SP)
  297.   MOVE.W #$20,-(SP)
  298.   TRAP #1
  299.   ADDQ #6,SP
  300. ;------------------
  301. ;Terminate normally
  302. ;
  303.   MOVEM.L (SP)+,A0-A6/D0-D7
  304.   MOVE.W #0,-(A7)
  305.   TRAP #1
  306. ;-----------------
  307. ;Keyboard interupt
  308. ;
  309. ;All we do here is change the
  310. ;priority of the keyboard interupt
  311. ;and jump to the original vector.
  312. ;
  313. KINT MOVE.W #$2500,SR
  314. KVEC EQU *+2
  315.   JMP $10000 ;Self modifying long jump
  316. ;-------------------------------------
  317. ;Vertical blank interupt
  318. ;
  319. ;The timer B interupt will be
  320. ;set to start during the horizontal blank just
  321. ;before the scan line (specified in the timer B
  322. ;data register) is displayed.  The screen resolution
  323. ;is set to low.  Setting the timer B data register
  324. ;to zero does not work.  Note that the instruction that
  325. ;sets the timer B data register is modified by the main program.
  326. ;The scan line number is relative to zero (i.e. 99 = 100th scan line)
  327. ;
  328. VBI MOVE.L D0,-(SP) ;Save register to be used
  329.   ADDQ.L #1,$466    ;Update VBI count
  330. ;
  331. CDATA EQU *+2
  332.   MOVE.W #99,D0     ;Data register for timer B (scan line 100)
  333.   MOVE.B D0,$FFFA21
  334. ;
  335. ;Calculate low word of address to test for in TIMERB code
  336. ;This could be done with a lookup table for speed if needed.
  337. ;If the scan line (where the rez changes) does not need to be
  338. ;moved, this calculation can be done by the programmer and
  339. ;hard coded.
  340. ;
  341. ;  (((D0+1)*160)-2)+$8000
  342. ;
  343.   ADDQ.W #1,D0
  344.   MULU #160,D0
  345.   SUBQ.W #2,D0
  346.   ADD.W #$8000,D0
  347.   MOVE.W D0,TADDR
  348. ;----------------------------------------------------------------
  349.   MOVEBW $08,$FA1B ;Control register for timer B (event counting)
  350.   MOVEBW $00,$8260 ;Set low rez
  351.   MOVE.L (SP)+,D0  ;Restore register
  352.   RTE
  353. ;----------------
  354. ;Timer B interupt
  355. ;
  356. ;Change resolution at a certain scan line
  357. ;
  358. ;There are 3 registers that specify the current
  359. ;address of display memory that is being fetched.
  360. ;
  361. ; $FF8205  Video address pointer (high byte)
  362. ; $FF8207  Video address pointer (mid byte)
  363. ; $FF8209  Video address pointer (low byte)
  364. ;
  365. ;Because our display memory is located at $78000, only the mid and
  366. ;low bytes of these registers will change.  Even though this interupt
  367. ;will be executed during the horizontal blank period just prior to
  368. ;the scan line specified in the timer B data register, it is not
  369. ;quite accurate enough to change the resolution at that point.  The
  370. ;reason for this is that certain 68000 instructions can take 100+
  371. ;machine cycles to execute.  This can cause the interupt to be delayed
  372. ;beyond the horizontal blank time period.  To get around this problem,
  373. ;the video address pointer registers are used.  When the interupt is
  374. ;executed, it executes a wait loop until the address of the last word
  375. ;of the scan line appears in the video address pointer registers, then
  376. ;the screen resolution is changed.  This guarantees that the change
  377. ;will occur during horizontal blank.
  378. ;
  379. ;There are a few minor drawbacks to this method.
  380. ;
  381. ;  1.  The resolution is changed beginning with the scan line
  382. ;      after the one specified in the timer B data register.
  383. ;      Zero cannot be used for the timer B data register.
  384. ;      Therefore, the earliest the resolution can be changed is
  385. ;      the third scan line.
  386. ;
  387. ;  2.  This process will waste quite a few cycles waiting for the
  388. ;      end of the scan line.  This could be minimized in an application
  389. ;      by having this interupt routine do some other quick task before
  390. ;      starting the wait loop (ex. update sound registers).
  391. ;
  392. ;  3.  Other interupts are disabled to insure that this one occurs at
  393. ;      the right time.  Some of the disabling might not be necessary.
  394. ;      The developer's documentation describes a method that will still
  395. ;      allow the system timer interupt to be used (sort of).
  396. ;
  397. ;This routine could easily be modified to change color registers as well.
  398. ;Note that the address value (used for comparison in the wait loop)
  399. ;is modified by the main program.
  400. ;
  401. TIMERB MOVE.L A0,-(SP) ;Save registers to be used
  402.   MOVE.W D0,-(SP)
  403. ;
  404.   CLR.W D0
  405.   MOVE.W D0,A0
  406. ;
  407. EOLLP MOVEP.W -$7DF9(A0),D0 ;$FF8207 = Current display address (low word)
  408. TADDR EQU *+2
  409.   CMP.W #$BE7E,D0           ;$8000+((100 * 160)-2)   (end of 100th scan line)
  410.   BCS.S EOLLP
  411. ;
  412.   MOVEBW $01,$8260 ;Set medium rez
  413.   MOVEBW $FE,$FA0F ;Clear in-service bit for timer B
  414.   MOVEBW $00,$FA1B ;Clear control register for timer B
  415. ;
  416.   MOVE.W (SP)+,D0  ;Restore registers
  417.   MOVE.L (SP)+,A0
  418.   RTE
  419. ;-----
  420.   DATA
  421.   CNOP 0,4
  422. ;----------------------------------------------------------
  423. ;Color pallette (all colors except background set to white)
  424. ;
  425. PALET DC.W $000,$777,$777,$777,$777,$777,$777,$777
  426.   DC.W $777,$777,$777,$777,$777,$777,$777,$777
  427. ;---------------------------------------------
  428. SAVE_SSP DS.L 1 ;Save system stack pointer
  429. SYSVBI DS.L 1   ;Save system vbi address
  430. ORGPAL DS.W 16  ;Save original color pallette
  431. SAVREZ DS.W 1   ;Save system resolution value
  432. SVSCR  DS.W 1   ;Save address of display memory
  433. ;----------------------------------------------
  434. CHTAB DS.B 96*8 ;ASCII character bit maps
  435. ;----------------------------------------
  436. ;By placing an ascii character code at
  437. ;MSG+4, and calling TOS, the character
  438. ;bit map will be drawn at (0,0).
  439. ;
  440. MSG DC.B $1B,'Y',$20,$20,0,0
  441. ;---------------------------
  442. ;ASCII characters
  443. ;
  444. ASCIT DC.B ' !""#$%&''()*+,-./'
  445.   DC.B '0123456789:;<=>?'
  446.   DC.B '@ABCDEFGHIJKLMNO'
  447.   DC.B 'PQRSTUVWXYZ[\]^_'
  448.   DC.B '`abcdefghijklmno'
  449.   DC.B 'pqrstuvwxyz{|}~ '
  450. ;
  451.   END
  452.